<?php
    $this->layout('base.phtml', [
        'title' => _('Link edition'),
        'canonical' => url_full('edit link', ['id' => $link->id]),
        'has_errors' => $form->isInvalid(),
        'modal_enabled' => true,
    ]);
?>

<div class="section">
    <div class="section__title">
        <h1 id="modal-title"><?= _('Link edition') ?></h1>
    </div>

    <p class="section__intro">
        <?= protect($link->title) ?>
    </p>

    <form data-turbo-preserve-scroll method="post" action="<?= url('update link', ['id' => $link->id]) ?>">
        <?= $this->include('alerts/_error.phtml', ['message' => $form->error('@base')]) ?>

        <div class="form-group">
            <label for="title">
                <?= _('The title of your link') ?>
            </label>

            <?php if ($form->isInvalid('title')): ?>
                <p id="title-error" class="form-group__error">
                    <?= _('Error:') ?>
                    <?= $form->error('title') ?>
                </p>
            <?php endif; ?>

            <input
                id="title"
                name="title"
                type="text"
                value="<?= protect($form->title) ?>"
                required
                autocomplete="off"
                autofocus
                aria-describedby="title-desc"
                <?php if ($form->isInvalid('title')): ?>
                    aria-errormessage="title-error"
                    aria-invalid="true"
                <?php endif; ?>
            />
        </div>

        <div class="form-group">
            <label for="reading-time">
                <?= _('It takes') ?>

                <input
                    id="reading-time"
                    name="reading_time"
                    type="number"
                    min="0"
                    class="input--number-3"
                    value="<?= $form->reading_time ?>"
                    required
                    autocomplete="off"
                    aria-describedby="reading-time-desc"
                    <?php if ($form->isInvalid('reading_time')): ?>
                        aria-errormessage="reading-time-error"
                        aria-invalid="true"
                    <?php endif; ?>
                />

                <?= _('minutes to consult.') ?>
            </label>

            <?php if ($form->isInvalid('reading_time')): ?>
                <p id="reading-time-error" class="form-group__error">
                    <?= _('Error:') ?>
                    <?= $form->error('reading_time') ?>
                </p>
            <?php endif; ?>
        </div>

        <div class="form__actions">
            <button type="submit" class="button--primary">
                <?= _('Save changes') ?>
            </button>
        </div>

        <input type="hidden" name="csrf_token" value="<?= csrf_token($form) ?>" />
    </form>
</div>
